#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int a[10] = {0, 1,};//砝码a1...a9
int b[10];//标记数组 b1=0
bool flag[1000001] = {0};

int main() {

    for (int i = 2; i <= 9; i++) {
        a[i] = a[i - 1] * i;
    }
    for (b[1] = 0; b[1] <= 1; b[1]++)
        for (b[2] = 0; b[2] <= 1; b[2]++)
            for (b[3] = 0; b[3] <= 1; b[3]++)
                for (b[4] = 0; b[4] <= 1; b[4]++)
                    for (b[5] = 0; b[5] <= 1; b[5]++)
                        for (b[6] = 0; b[6] <= 1; b[6]++)
                            for (b[7] = 0; b[7] <= 1; b[7]++)
                                for (b[8] = 0; b[8] <= 1; b[8]++)
                                    for (b[9] = 0; b[9] <= 1; b[9]++) {
                                        int x = 0;
                                        for (int i = 1; i <= 9; i++) {
                                            x += a[i] * b[i];
                                        }
                                        flag[x] = 1;
                                    }
    int T;
    cin >> T;
    while (T--) {
        int x;
        cin >> x;
        cout << flag[x] << endl;

    }

    return 0;
}